package uplift.project;

import java.util.ArrayList;

import uplift.project.model.Suggestion;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SuggestionAdapter extends ArrayAdapter<Suggestion> {

	private ArrayList<Suggestion> items;

	public SuggestionAdapter(Context context, int textViewResourceId, ArrayList<Suggestion> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.suggestion_list_item, null);
		}
		Suggestion sugg = items.get(position);
		if (sugg != null) {
			TextView name = (TextView) v.findViewById(R.id.suggestion_list_name);
			ImageView image = (ImageView) v.findViewById(R.id.suggestion_list_image);
			if (name != null) {
				name.setText(sugg.getName());                            
			}
			if(image != null){
				image.setImageResource(sugg.getImageRes());
			}
		}
		return v;
	}
}
